package pl.put.dcs.workManagerServer.projectManager.computingObjectManger;

import pl.put.dcs.workManagerServer.projectManager.computingObjectManger.packetManager.PacketManager;
import pl.put.dcs.workManagerServer.serviceConnectors.ControlModuleServerConnectorInterface;
import pl.put.dcs.workManagerServer.serviceConnectors.ControlModuleServerConnector;
import pl.put.model.packet.Packet;
import pl.put.model.flowModel.flowComputingObjectElement.FlowComputingObjectElement;

public class ComputingObjectManger
{
    
    
    private FlowComputingObjectElement flowComputingObjectElement;
    private PacketManager packetManager;

    public ComputingObjectManger( FlowComputingObjectElement computingObject )
    {
        flowComputingObjectElement = computingObject;
        PacketManager pm = new PacketManager( computingObject );
        setPacketManager( pm );
    }

    public PacketManager getPacketManager()
    {
        return packetManager;
    }

    public void setPacketManager( PacketManager val )
    {
        packetManager = val;
    }

    /**
     * Czy wszystkie zadania zostaly przydzielone i juz zakonczone.
     * @return boolean Jezeli tak, to True
     */
    public boolean isFinish()
    {
        ControlModuleServerConnectorInterface ctrlModule = ControlModuleServerConnector.getInstance();
        boolean isFinish = !hasMoreTasks() && ( ctrlModule.countActiveTasks( flowComputingObjectElement ) == 0 );
        return isFinish;
    }

    public Packet createPacket()
    {
        return packetManager.createPacket();
    }

    public FlowComputingObjectElement getFlowComputingObjectElement()
    {
        return flowComputingObjectElement;
    }

    public void setFlowComputingObjectElement( FlowComputingObjectElement val )
    {
        flowComputingObjectElement = val;
    }

    /**
     * Czy sa jeszcze jakies taski (pakiety) do wygenerowania?
     * @return boolean True jezeli tak;.
     */
    public boolean hasMoreTasks()
    {
        return packetManager.hasMorePackets();
    }
}

